<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>运费</title>
    <%layout("/WEB-INF/view/common/inc/admin_head.html",{title:'', styles:'bootstrap,font-awesome,animate,style,bootstrap-table,layui-date,auto-complete,dtvalidate,layer,layui'}){%>
    <style type="text/css">
        body{padding-top:10px;}
        *{margin:0;padding:0;list-style-type:none;}
        a,img{border:0;}
        .demo h2{font-size:16px;color:#3366cc;height:30px;}
        .demo li{float:left;}
    </style>
    <%}%>
</head>
<body>
<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins" style="margin-bottom: 0px;">
                <div class="ibox-content" style="padding:15px 20px 0px 20px;">
                    <form id="search-form" role="form" class="form-horizontal" autocomplete="off">
                        <input type="hidden" id="type" name="type" value="2">
                        <div class="form-group">
                            <label class="control-label col-sm-1">柜号:</label>
                            <div class="col-sm-2">
                                <input type="text" class="form-control" id="createPlanNo" name="createPlanNo">
                            </div>
                            <label class="control-label col-sm-1">供应商:</label>
                            <div class="col-sm-2">
                                <input type="text" id="createSupplier" name="createSupplier" class="form-control">
                            </div>
                            <label class="control-label col-sm-1">类型:</label>
                            <div class="col-sm-2">
                                <select id="flag" name="flag" class="form-control">
                                    <option value="">全部</option>
                                    <option value="0">运费</option>
                                    <option value="1">关税</option>
                                    <option value="2">头程</option>
                                    <option value="3">海运</option>
                                    <option value="4">尾程</option>
                                </select>
                            </div>

                        </div>
                        <div class="form-group">
                            <label class="control-label col-sm-1">付款:</label>
                            <div class="col-sm-2">
                                <select id="createPay" name="createPay" class="form-control">
                                    <option value="">全部</option>
                                    <option value="0">否</option>
                                    <option value="1">是</option>
                                </select>
                            </div>

                            <label class="control-label col-sm-1">付款方式:</label>
                            <div class="col-sm-2">
                                <select  name="createPayType" id="createPayType" class="form-control">
                                    <option value="">请选择付款方式</option>
                                    <%for(var dict in payment){%>
                                    <option value="${dict.detailName}"  >${dict.detailName}</option>
                                    <%}%>
                                </select>
                            </div>
                            <label class="control-label col-sm-1">币种:</label>
                            <div class="col-sm-2">
                                <select class="form-control" id="createMoneyType" name="createMoneyType">
                                    <option value="">币种</option>
                                    <option value="人民币">人民币</option>
                                    <option value="美金">美金</option>
                                    <option value="加元">加元</option>
                                    <option value="欧元">欧元</option>
                                    <option value="英镑">英镑</option>
                                    <option value="日元">日元</option>
                                    <option value="埃及镑">埃及镑</option>
                                </select>
                            </div>
                            <a class="search-btn btn  btn-success" >查询</a>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<div id="toolbar" class="btn-group" style="margin-bottom:5px;">
    <button  class="export-btn layui-btn  layui-btn-sm" >
        <i class="fa fa-download" aria-hidden="true"></i> 导出当前数据
    </button>
    <button  class="report-btn layui-btn  layui-btn-sm btn-info"  style="">
        <i class="fa fa-check-square-o" aria-hidden="true"></i> 批量付款
    </button>
</div>
<!-- START 数据表格 -->
<table id="freightTable"
       data-toolbar="#toolbar"
       data-pagination="true"
       data-resizable="true"
       data-side-pagination="server"
       data-url="/sea/finance/freight/findByCnd.do"
       data-page-size="15"
       class="table table-striped table-hover"
>
</table>

<div id="layer_window" style="display: none;overflow-x: hidden">
    <div class="form-group">
        <label class="control-label col-sm-2" style="margin-top: 15px;padding-top: 6px;">实际运费</label>
        <div class="col-sm-9" style="margin-top: 15px;width: 300px;">
            <input type="text" class="form-control" id="dispatchActFreight" name="dispatchActFreight" onkeyup="value=value.replace(/[^\d?.{1}\d{2}]/g,'')">
        </div>
    </div>
</div>


<div id="layer_all_window" style="display: none;overflow-x: hidden;overflow-y: hidden">
    <!-- START 内容部分 -->
    <div class="container" >
        <form class="form-horizontal" id="info-form" method="post" autocomplete="off" style="margin: auto">

            <div class="form-group" style="margin-top: 20px">
                <label class=" control-label col-sm-2" style="max-width: 100px">付款时间</label>
                <div class="col-sm-6" style="max-width: 400px;">
                    <input type="text" name="producePayTime" id="producePayTime" class="form-control" >
                </div>
            </div>
            <div class="form-group" style="margin-top: 20px">
                <label class=" control-label col-sm-2" style="max-width: 100px">上传凭证</label>
                <div class="col-sm-6" style="max-width: 400px;">
                    <a class="club-import-btn ">
                        <input type="file" id="importSession2" name="importSession">
                    </a>
                    <input type="hidden" name="produceFile2" id="produceFile2">
                </div>
            </div>

            <div class="form-group" style="margin-top: 20px">
                <label class="control-label col-sm-7" style="max-width: 100px"></label>
                <button type="button" class="save-all-btn btn btn-primary">
                    <i class="fa fa-save"></i> 保存
                </button>
            </div>
        </form>
    </div>
    <!-- END 内容部分 -->
</div>
<%layout("/WEB-INF/view/common/inc/admin_js.html",{modules:'jquery,bootstrap,bootstrap-table,dtvalidate,dtvalidate-lang-zh_cn,bootstrap-table-zh-CN,laydate,layer,layui'}){}%>
<script>
    laydate.render({
        elem: '#producePayTime',
        type: 'date',
        format: 'yyyy-MM-dd',
        trigger: 'click'
    });

    var $freightTable = $('#freightTable');

    $(function () {

        // START 表格配置
        $freightTable.bootstrapTable({
            queryParams : function (params) {
                //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
                var temp = {
                    type: 2,
                    limit: params.limit,     //页面大小
                    offset: params.offset    //页码
                };
                return temp;
            },
            pageSize:10,

            columns: [
                {
                    field: 'state',
                    checkbox: true,
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '柜号',
                    field: 'createPlanNo',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '供应商',
                    field: 'createSupplier',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '币种',
                    field: 'createMoneyType',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '金额',
                    field: 'createMoney',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '汇率',
                    field: 'createMoneyPercent',
                    align: 'center',
                    valign: 'middle'
                },

                {
                    title: '类型',
                    field: 'flag',
                    align: 'center',
                    valign: 'middle',
                    formatter:function (v,r) {
                        if(v==0){
                            return '运费';
                        }else if(v==1){
                            return '关税';
                        }
                        else if(v==2){
                            return '头程';
                        }
                        else if(v==3){
                            return '海运';
                        }
                        else if(v==4){
                            return '尾程';
                        }
                    }
                },
                {
                    title: '是否付款',
                    field: 'createPay',
                    align: 'center',
                    valign: 'middle',
                    formatter:function (v,r) {
                        if(v==0){
                            return '否';
                        }else{
                            return '是';
                        }
                    }
                },
                {
                    title: '付款凭证',
                    field: 'createPayFile',
                    align: 'center',
                    valign: 'middle',
                    formatter:function (v,r) {
                        if(v!='' && null!=v){
                            var result='<button  class="download-btn layui-btn  layui-btn-sm"  style="margin-top: -6px;margin-left: -4px">';
                            result+='<i class="fa fa-download" aria-hidden="true"></i> <a href="'+v+'" download style="color: white">下载附件</a>';
                            result+='</button>';
                            return result;
                        }
                    }
                },
                {
                    title: '付款时间',
                    field: 'createPayTime',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '付款方式',
                    field: 'createPayType',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '备注',
                    field: 'createRemark',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '创建时间',
                    field: 'createTime',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '操作',
                    field: 'operate',
                    align: 'center',
                    valign: 'middle',
                    formatter: optFormatter
                }
            ],
            onLoadSuccess : function(){

                $('.edit-btn').on('click',function(){//新增
                    var id=$(this).attr('data-val');
                    layer.open({
                        title: false,
                        closeBtn: 0,
                        type: 2,
                        area: ['100%','100%'],
                        skin: 'layer-ext-espresso',
                        content: ['/sea/finance/freight/editPage.do?id='+id, 'yes']
                    });
                });
            }
        });

        //初始化子表格(无线循环)
        var cur_table ='';

        // 条件查询
        $('.search-btn').on('click',function () {
            $freightTable.bootstrapTable('refresh', { url:'${ctxPath}/sea/finance/freight/findByCnd.do?'+$('#search-form').serialize() });
        });
        // 导出当前数据
        $('.export-btn').on('click',function () {
            window.location.href='/sea/finance/freight/export.do?'+$('#search-form').serialize();
        })

        //操作菜单
        function optFormatter(value,row){
            var content='';
            if(row.createPay==0) {
                content += '<button class="edit-btn btn btn-xs btn-info" data-val="' + row.id + '" title="付款"><i class="fa fa-edit"></i> 付款</button>';
            }
            return content;
        }
    });

    $('.report-btn').on('click',function () {
        var selDatas = $freightTable.bootstrapTable('getSelections');
        if( selDatas.length == 0 ){
            layer.msg('请选择要生成的数据',{icon: 0,shade: [0.8, '#393D49'],time: 1500});
        }else {
            layer.open({
                type: 1,
                title: '批量付款',
                area: ['600px', '450px'],
                skin: 'layui-layer-lan',//layui-layer-molv ;layui-layer-lan;layui-layer-rim;layer-window
                shadeClose: false,
                resize: false,
                scrollbar: false,
                maxmin: false,//出现最大化按钮
                content: $('#layer_all_window')
            })
        }
    });
    $("#importSession2").on("change",function(){
        var formFile = new FormData($('#info-form')[0]);
        var index=layer.load(1, {
            shade: [0.1,'#fff'],
            zIndex : 1111//0.1透明度的白色背景
        });
        var index= layer.load(2, { //icon支持传入0-2
            shade: [0.1, '#fff'], //0.5透明度的灰色背景
            content: '正在上传凭证,请稍后...',
            success: function (layero) {
                layero.find('.layui-layer-content').css({
                    'padding-top': '39px',
                    'margin-left': '-50px',
                    'width': '300px',
                    'font-color': 'red',
                    'font-size': '20px'
                });
            }
        });
        $.ajax({
            url: "/upload/uploadFile",
            data: formFile,
            type: "post",
            processData: false,//用于对data参数进行序列化处理 这里必须false
            contentType: false, //必须
            success: function (data) {
                console.log(data);
                if(data.ok){
                    parent.layer.msg("上传成功！",{icon: 0,time:1500,shade: [0.8, '#393D49']});
                    $("#produceFile2").val(data.data);
                    layer.close(index);
                }else{
                    parent.layer.msg(data.msg,{icon: 0,time:1500,shade: [0.8, '#393D49']});
                    layer.close(index);
                }
            },
        });
    });

    $(".save-all-btn").on('click',function () {

        var selDatas = $freightTable.bootstrapTable('getSelections');
        if( selDatas.length == 0 ){
            layer.msg('请选择要生成的数据',{icon: 0,shade: [0.8, '#393D49'],time: 1500});
        }else{
            var producePayTime=$("#producePayTime").val();
            var produceFile2=$("#produceFile2").val();
            var ids = [];
            var flag=true;
            $.each(selDatas,function(i,d){
                ids.push(d.id);
            });
            ids = ids.join(',');
            if(flag==true) {
                var inde= layer.load(2, { //icon支持传入0-2
                    shade: [0.1, '#fff'], //0.5透明度的灰色背景
                    content: '正在批量付款,请稍后...',
                    success: function (layero) {
                        layero.find('.layui-layer-content').css({
                            'padding-top': '39px',
                            'margin-left': '-50px',
                            'width': '300px',
                            'font-color': 'red',
                            'font-size': '20px'
                        });
                    }
                });
                $.ajax({
                    url: "/sea/finance/freight/pay",
                    data: {
                        producePayTime:producePayTime,
                        produceFile:produceFile2,
                        payIds:ids
                    },
                    type: "post",
                    success: function (data) {
                        if(data.ok){
                            layer.msg("生成成功！",{icon: 0,btn: ['确定'],time:0,shade: [0.8, '#393D49'],yes: function(index, layero){ // 默认的是 按钮一
                                    layer.closeAll();
                                    $freightTable.bootstrapTable('refresh');
                                }});
                        }else{
                            layer.msg(data.msg,{icon: 0,btn: ['确定'],time:0,shade: [0.8, '#393D49'],yes: function(index, layero){ // 默认的是 按钮一
                                    layer.closeAll();
                                }});
                        }
                    },
                });
            }
        }
    })
</script>
</body>
</html>